/*
package com.sky.task;

import com.sky.entity.Orders;
import com.sky.mapper.OrderMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;
import java.util.Date;
import java.util.List;

@Component
@Slf4j
public class OrderTask {
    @Autowired
    private OrderMapper orderMapper;

    //定时任务每一分钟触发一次
    @Scheduled(cron = "0/1 * * * * ?")
    public void  executeTask(){
        log.info("定时任务开始执行：{}",new Date());
        LocalDateTime time = LocalDateTime.now().plusMinutes(-15);
        List<Orders> orderList = orderMapper.getByStatusAndOrderTime(Orders.PENDING_PAYMENT, time);
        for(Orders orders:orderList){
            orders.setStatus(Orders.CANCELLED);
            orders.setCancelReason("订单超时，取消订单");
            orders.setCancelTime(LocalDateTime.now());
            orderMapper.update(orders);
        }

    }


    //定时任务每天1点触发一次
    @Scheduled(cron = "0 0 1 * * ?")
    public void  processDeliveryOrder(){
        log.info("定时处理派送中的订单：{}",LocalDateTime.now());
        LocalDateTime time = LocalDateTime.now().plusMinutes(-60);
        List<Orders> orderList = orderMapper.getByStatusAndOrderTime(Orders.DELIVERY_IN_PROGRESS,time);
        for(Orders orders:orderList){
            orders.setStatus(Orders.COMPLETED);
            orderMapper.update(orders);
        }
        }






}
*/
